package LeetCode;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class Code406_reconstructQueue {

    public int[][] reconstructQueue(int[][] people) {
        if (people == null || people.length == 0 || people[0].length == 0){
            return new int[0][];
        }
        Arrays.sort(people, ((o1, o2) ->
                o1[0] == o2[0] ? o1[1] - o2[1] : o2[0] - o1[0]));
        List<int[]> res = new ArrayList<>();
        for (int[] temp : people){
            res.add(temp[1], temp);
        }
        return res.toArray(new int[0][]);
    }
}
